angular.module('starter.myself', [])
  .controller('myselfPersonalSettingsCtrl', function($scope, $stateParams, $faAPI, $faUser, $faModal) {
    $faUser.update();
  })
  .controller('myselfLogpwdCtrl', function($scope, $stateParams, $faAPI, $faUser, $faModal, $ionicActionSheet, $faPopup, $state, $faUtil, $ionicHistory, $rootScope) {

    $faUser.update();
    $scope.userChangePassword = {
      isShowPassword: false
    };

    $scope.doUpdate = function(){
      if(!$scope.userChangePassword.oldLoginPwd){
        $faPopup.alert({
          title: '请输入原登录密码'
        });
        return;
      }
      if(!$scope.userChangePassword.loginPwd){
        $faPopup.alert({
              title: '请输入新密码'
          });
        return;
      }else if($scope.userChangePassword.loginPwd.length < 6 || $scope.userChangePassword.loginPwd.length > 18){
        $faPopup.alert({
          title: '密码长度要再6-18位之间'
        });
        return;
      }else{
        if($scope.userChangePassword.loginPwd != $scope.userChangePassword.loginPwd2){
          $faPopup.alert({
            title: '两次密码输入不一致！'
          });
          return;
        }
      }

      $faAPI.myself.chgLoginPwd($scope.userChangePassword).then(function(json){
        if(json){
          if(!json.statusCode){
            $faPopup.alert({
              title: '修改成功！'
            });
            
            $faUtil.localStorage.remove('_token');
            $faUtil.cookie.remove('_token', {path: '/'});
            $faAPI.user.logout().then(function() {
              $faUser.info = {
                isLogin: false,
                mobile: $faUser.info.mobile
              };

              $faUtil.localStorage.remove('user');
              $faUtil.localStorage('user', $faUser.info);

              $ionicHistory.nextViewOptions({
                disableBack: true
              });

              //$rootScope.isUserLogin = '0';
              $faUser.update();

              $state.go('app.myself');
            });
          }
        }
      });
    }

  })
  .controller('myselfZfpwdCtrl', function($scope, $stateParams, $faAPI, $faUser, $faModal, $ionicActionSheet, $faPopup, $state, $ionicPopup) {
    $faUser.update();
    $scope.user = {};

    $faAPI.pay.payCheck().then(function(json){
      if(json){
        if(!json.tradePwd || json.tradePwd == 0){
          // 提示设置交易密码
          var myPopup = $ionicPopup.show({
            title: '请先设置交易密码',
            scope: $scope,
            buttons: [
              { 
                text: '取消',
                type: 'confirmLoginCancel',
                onTap: function(e) {
                  $state.go('app.myself.settings');
                }
              },
              {
                text: '去设置',
                  type: 'button-positive confirmLogin',
                  onTap: function(e) {
                      $state.go('app.tradePassword');
                  }
              }
            ]
          });

        }
      }
    });

    $scope.doUpdate = function(){
      if(!$scope.user.loginPwd){
        $faPopup.alert({
          title: '请输入登录密码'
        });
        return;
      }
      if(!$scope.user.oldTradePwd){
        $faPopup.alert({
          title: '请输入原交易密码'
        });
        return;
      }
      if(!$scope.user.tradePwd){
        $faPopup.alert({
          title: '请输入新密码'
        });
        return;
      }else if($scope.user.tradePwd.length != 6 || isNaN($scope.user.tradePwd)){
        $faPopup.alert({
          title: '交易密码只能是六位数字！'
        });
        return;
      }else{
        if($scope.user.tradePwd != $scope.user.tradePwd2){
          $faPopup.alert({
            title: '两次密码输入不一致！'
          });
          return;
        }
      }

      $faAPI.myself.changTradePwd($scope.user).then(function(json){
        if(json){
          if(!json.statusCode){
            $faPopup.alert({
              title: '修改成功！'
            });
            $state.go('app.myself.settings');
          }
        }
      });
    }

  })
  .controller('myselfZhpwdCtrl', function($ionicPopup, $scope, $stateParams, $faAPI, $faUser, $faModal, $ionicActionSheet, $interval, $faPopup, $state, $rootScope) {
    $faUser.update();
    $scope.userGetTrade = {};
    var changeState = $stateParams.cs;

    $faAPI.pay.payCheck().then(function(json){
      if(json){
        if(!json.tradePwd || json.tradePwd == 0){
          // 提示设置交易密码
          var myPopup = $ionicPopup.show({
            title: '请先设置交易密码',
            scope: $scope,
            buttons: [
              { 
                text: '取消',
                type: 'confirmLoginCancel',
                onTap: function(e) {
                  $state.go('app.myself.settings');
                }
              },
              {
                text: '去设置',
                type: 'button-positive confirmLogin',
                onTap: function(e) {
                  $state.go('app.tradePassword');
                }
              }
            ]
          });

        }
      }
    });

    var isGetSmsCode = false;
    $scope.overTime = 120;

    $scope.getSmsCode = function(){
      // console.log($scope.userGetTrade.smsCode);
      //if(!$scope.userGetTrade.smsCode){
      //  $faPopup.alert({
      //    title: '请输入手机号！'
      //  });
      //  return;
      //}

      // 获取验证码
      $faAPI.media.sendLoginVcode({mobile: $faUser.info.mobile}).then(function(json){
        if(json.AB) {
          $faPopup.alert({
            title: '短信请求过于频繁，请稍候再试！'
          });
        } else {
          if(json) {
            $scope.overTime = 120;

          $interval(function () {
            $scope.overTime--;
          }, 1000, 120);
        }
    }
  });
    };

    $scope.doUpdate = function(){
      if(!$scope.userGetTrade.loginPwd){
        $faPopup.alert({
          title: '请输入登录密码！'
        });
        return;
      }
      if(!$scope.userGetTrade.tradePwd){
        $faPopup.alert({
          title: '请输入交易密码！'
        });
        return;
      }else if($scope.userGetTrade.tradePwd.length != 6 || isNaN($scope.userGetTrade.tradePwd)){
        $faPopup.alert({
          title: '交易密码只能是六位数字！'
        });
        return;
      }else{
        if($scope.userGetTrade.tradePwd != $scope.userGetTrade.tradePwd2){
          $faPopup.alert({
            title: '两次密码不一致！'
          });
          return;
        }
      }
      if(!$scope.userGetTrade.smsCode){
        $faPopup.alert({
          title: '请输入验证码！'
        });
        return;
      }

      $faAPI.myself.forgetTradePwd($scope.userGetTrade).then(function(json){
        if(json){
          if(!json.statusCode){
            $faPopup.alert({
              title: '修改成功！'
            });

            if(changeState){
              if(changeState == '1'){
                $state.go('app.withdraw.do', {id: $rootScope.doWithdrawId || 0});
              }
            }else{
              $state.go('app.myself.settings');
            }
          }
        }
      });

    }

  })
  .controller('myselfCertificationCtrl', function($ionicLoading, $ionicNavBarDelegate,$faUtil,$ionicHistory,$rootScope, $scope, $stateParams, $faAPI, $faUser, $faModal, $ionicActionSheet, $timeout, $faMAP, $faUploader, $faPopup, $state, $ionicPopup, $faPlatform) {
    $faUser.update();
    $scope.isShowUpload = false;
    $scope.cardAddress = '';
    $scope.repage = $stateParams.repage;
    $scope.isShowUploadButton = false;
    $scope.isShowUploadOk = false;
    $scope.imageType = '1';
    $scope.isshowback = $stateParams.isshowback?true:false;
    //console.log($scope.isshowback);
    //if($stateParams.isshowback){
    //  $ionicNavBarDelegate.showBackButton(true);
    //}else {
    //  console.log('$ionicNavBarDelegate');
    //  $ionicNavBarDelegate.showBackButton(false);
    //}


    var pictureSource; // picture source
    var destinationType; // sets the format of returned value 

    $timeout(function(){
      if($faUser.info.role == '1' || $faUser.info.role == '99'){
        // 未提交或审核失败
        if($faUser.info.role == '1'){
          $scope.isShowUpload = true;
        }else{
          $scope.isShowUpload = false;
          $scope.cardAddress = $faUser.info.cardAddress;
        }

        $scope.isShowUploadButton = true;

        // if(!$faPlatform.IOSAPP && !$faPlatform.androidAPP){
          // 不是Android、也不是IOS
        var t = document.getElementById('up-img');
        t.addEventListener('change', function(e){

          doUpload(e);
        });
        // }else{
        //   // 手机APP环境
        //   pictureSource = navigator.camera.PictureSourceType;
        //   destinationType = navigator.camera.DestinationType;
        // }

      }else{
        $scope.isShowUpload = false;
        $scope.cardAddress = $faUser.info.cardAddress;
      }

      // if($faUser.info.cardAddress){
      //   if($faUser.info.cardAddress.indexOf('data:image') >= 0){
      //     $scope.imageType = '2';
      //   }
      // }
    }, 100);

    $scope.toGetPhoto = function(){
      var myPopup = $ionicPopup.show({
        scope: $scope,
        buttons: [
          {
            text: '取消',
            onTap: function(e){
              myPopup.close();
            }
          },
          {
            text: '摄像机',
            type: 'button-positive',
            onTap: function(e){
              myPopup.close();
              $scope.capturePhoto(1);
            }
          },
          {
            text: '相册',
            type: 'button-positive',
            onTap: function(e){
              myPopup.close();
              $scope.capturePhoto(2);
            }
          }
        ]
      });
    }

    function onPhotoDataSuccess(imageData) {
      $scope.imageType = '2';
      $scope.cardAddress = "data:image/jpeg;base64," + imageData;
      $scope.isShowUpload = false;
      $scope.isShowUploadOk = true;
    }

    $scope.capturePhoto = function(t) {
      if(t == 1){
        // 摄像头
        navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
          quality: 50,
          destinationType: destinationType.DATA_URL
        });
      }else if(t == 2){
        // 相册
        navigator.camera.getPicture(onPhotoDataSuccess, onFail, {
          quality: 50,
          destinationType: destinationType.DATA_URL,
          sourceType: pictureSource.PHOTOLIBRARY
        });
      }
    }

    function onFail(message) {
      $faPopup.alert({ title: message });
    }

    $scope.updataFile = {
      currentSize: 0,
      totalSize: 0,
      percent:0,
      isShowLoading: false
    };

    function doUpload(e){
      var files = e.target.files;
      var fileSize = files[0].size;

      //if (!$faMAP.regular.image.test(files[0].type)) {
      //  $faPopup.alert({
      //    title: '上传的文件格式不对'
      //  });
      //  $element.removeClass('ng-hide');
      //  $element[0].value = '';
      //  return;
      //} else
      if (fileSize > 5242880) {
        $faPopup.alert({
          title: '上传的文件太大了'
        });
        $element.removeClass('ng-hide');
        $element[0].value = '';
        return;
      } else if (fileSize < 5120) {
        $faPopup.alert({
          title: '上传的文件太小了'
        });
        $element.removeClass('ng-hide');
        $element[0].value = '';
        return;
      }

      $faUploader.removeAll();
      $faUploader.addFiles(files);
      $scope.files = $faUploader.getFiles();

      $scope.updataFile.isShowLoading = true;
      $scope.updataFile.percent = 0;

      var baseUrl = '';
      if(!$faPlatform.IOSAPP && !$faPlatform.androidAPP){
        baseUrl = fileUploadUrl;
      }else{
        baseUrl = reqUrl + fileUploadUrl;
      }

      $faUploader.startUpload({
        url: baseUrl,
        concurrency: 2,
        onProgress: function(file) {
          if(file.loaded <= fileSize){
            $scope.updataFile.percent = ((file.loaded / fileSize) * 100).toFixed(2);
          }else{
            $scope.updataFile.percent = 1;
            $scope.updataFile.isShowLoading = false;
          }

          $scope.$apply();
        },
        onCompleted: function(file, res) {
          var res = angular.fromJson(res);

          if (res.statusCode === '0000') {
            var uri = res.attributes.fileUrl;
            $scope.cardAddress = uri;
            $scope.imageType = '1';
            $scope.isShowUpload = false;
            $scope.isShowUploadOk = true;
          } else {
            $faPopup.alert({
              title: $faMAP.statusCode[res.statusCode]
            });
          }
          $scope.$apply();
        }

      });
    }

    $scope.doUpdate = function(){

      if($scope.cardAddress && $scope.cardAddress.length > 0){
        $faAPI.user.card({uCardAddress: $scope.cardAddress}).then(function(json) {
          $faUser.update();
          var alertPopup = $ionicPopup.alert({
            title: '上传成功！'
          });
          alertPopup.then(function(res) {
            if($scope.repage && $scope.repage.length > 0){
              $state.go('app.upload');
            }
          });
          $scope.isShowUploadButton = false;
          $scope.isShowUploadOk = false;
        }, function(jj){
          console.log(jj);
        });
      }
    };

    $scope.logout = function() {
      var myPopup = $ionicPopup.show({
        title: '下次登录依然可以使用本账号',
        scope: $scope,
        buttons: [
          {
            text: '取消',
            type: 'confirmLoginCancel'
          },
          {
            text: '确定退出',
            type: 'button-positive confirmLogin',
            onTap: function(e) {

              $faUtil.localStorage.remove('_token');
              $faUtil.cookie.remove('_token', { path: '/' });

              $faAPI.user.logout().then(function() {

                $faUser.info = {
                  isLogin: false,
                  mobile: $faUser.info.mobile
                };

                $faUtil.localStorage.remove('user');
                $faUtil.localStorage('user', $faUser.info);

                $rootScope.userRole = null;

                $ionicHistory.nextViewOptions({ disableBack: true });

                $faUser.update();
                $state.go('app.myself');
                $rootScope.modal.login();

                //用来更新产品列表的登录或者认证状态
                //微信简版版本登录认证状态后台配置--add
                //window.location.reload();
              });
            }
          }
        ]
      });
    };

  })

    .controller('orderIndexCtrl', function ($scope, $rootScope, $stateParams,$state,$ionicPopup, $faAPI,$ionicScrollDelegate, $faUser, $faPopup, $faModal, $q, $ionicLoading, $timeout, $faUtil, $faPlatform) {
        //我的订单

        $scope.payStatusStage = '';

        $scope.pager = {
            pageSize: 10,
            pageNo: 1,
            hasNaxtPage: true,
            payStatusStage:$scope.payStatusStage
        };



        $scope.currentOutOrIn = 'out';
        var isFirstLoad = true;

        $scope.outOrder = {};
        $scope.outOrderList = {};
        $scope.inOrder = {};
        $scope.inOrderList = {};

        $scope.changeOutOrIn = function (t) {
            if (t) {
                if (!$faUser.info.isLogin) {
                    // 要登录
                    $rootScope.modal.login();
                    $scope.pager.hasNaxtPage = false;
                    return;
                }

                $scope.currentOutOrIn = t;

                $scope.outOrder = {};
                $scope.outOrderList = {};
                $scope.inOrder = {};
                $scope.inOrderList = {};

                $scope.pager = {
                    pageSize: 10,
                    pageNo: 1,
                    hasNaxtPage: false
                };
                isFirstLoad = true;

                $scope.loadMore();
            }
        };

        $scope.loadMore = function () {

            if ($scope.currentOutOrIn) {
                if (!isFirstLoad) {
                    $scope.pager.pageNo++;
                } else {
                    isFirstLoad = false;
                }
                $scope.pager.payStatusStage = $scope.payStatusStage;
                if ($scope.currentOutOrIn == 'out') {
                    $faAPI.order.list($scope.pager).then(function (json) {
                        if (json) {
                            $scope.outOrder = json;

                            if ($scope.outOrderList && $scope.outOrderList.length >= 1) {
                                $scope.outOrderList = $scope.outOrderList.concat(json.list);
                            } else {
                                $scope.outOrderList = json.list;
                            }
                            $scope.pager = json.pager;
                            $scope.$broadcast('scroll.infiniteScrollComplete');
                        }
                    });
                } else if ($scope.currentOutOrIn == 'in') {
                    $faAPI.order.inOrderProductList($scope.pager).then(function (json) {
                        if (json) {
                            $scope.inOrder = json;
                            if ($scope.inOrderList && $scope.inOrderList.length >= 1) {
                                $scope.inOrderList = $scope.inOrderList.concat(json.list);
                            } else {
                                $scope.inOrderList = json.list;
                            }
                            $scope.pager = json.pager;
                            $scope.$broadcast('scroll.infiniteScrollComplete');
                        }
                    });
                }
            }
        };
        $scope.doRefresh = function(){

            $faAPI.order.list({
                pageNo:1,
                pageSize:10,
                payStatusStage:$scope.payStatusStage
            }).then(function (json) {
                if (json) {
                    $scope.outOrder = json;

                    $scope.outOrderList = json.list;
                    $scope.pager = json.pager;
                    $scope.$broadcast('scroll.refreshComplete');
                }
            });
        };
        //$scope.$on('$stateChangeSuccess', function () {
        //    $scope.loadMore();
        //});

        //产品tab页的推荐
        $scope.hotList = {};
        $scope.issle = 1;
        var sledivs, sletabview;

        $scope.flagShopQuery = '';

        // sledivs = document.querySelectorAll('#orderslelist>div');
        // sletabview = document.getElementById('ordersletabview');
        sledivs = angular.element(sledivs);
        sletabview = angular.element(sletabview);
        $scope.isTab = 1;
        $scope.tabShow = function (e) {
            //初始化排序条件
            $scope.isTab = 1;
            $scope.isTab = e;
            if($scope.isTab == 1){
                $scope.payStatusStage = "";
                $scope.goTop()
            }
            if($scope.isTab == 2){
                $scope.payStatusStage = 1;
                $scope.goTop()
            }
            if($scope.isTab == 3){
                $scope.payStatusStage = 4;
                $scope.goTop()
            }
            if($scope.isTab == 4){
                $scope.payStatusStage = 5;
                $scope.goTop()
            }
            $scope.pager.pageNo = 1;
            $scope.pager.pageSize = 10;

            isFirstLoad = true;
            $scope.outOrderList = [];
            $scope.loadMore();
        }
        $scope.orderTab = 1;
        //监听isTab
        $scope.$watch('isTab',function(newval,oldval,scope) {
            if (newval != 2) {
                $scope.orderTab = 1;
            }

        })
        $scope.orderList = function (tab) {

            // $scope.isTab = 1;
            $scope.orderTab = tab;
            if($scope.orderTab == 1){
                $scope.payStatusStage = 1;
                $scope.goTop()
            }
            if($scope.orderTab == 2){
                $scope.payStatusStage = 2;
                $scope.goTop()
            }
            if($scope.orderTab == 3){
                $scope.payStatusStage = 3;
                $scope.goTop()
            }
          /* $scope.pager.pageNo = 1;
           $scope.pager.pageSize = 10;*/

            isFirstLoad = true;
            $scope.outOrderList = [];
            $scope.loadMore();
        }

        // for (var i = 0; i < sledivs.length; i++) {
        //     sledivs[i].index = i;
        //     sledivs[i].onclick = function (e) {
        //         clearClass();
        //         this.className = 'w4-prolist-sle';
        //
        //         $scope.index = this.index;
        //         //初始化排序条件
        //         $scope.issle = 1;
        //         $scope.$digest();
        //         //$rootScope.sletype = this.index;
        //         console.log(this.index);
        //         if (this.index == 0) {
        //             $scope.payStatusStage = '';
        //         }
        //         if (this.index == 1) {
        //             $ionicScrollDelegate.$getByHandle('mainScroll').scrollTo(0, 0, true);
        //             $scope.payStatusStage = 1;
        //         }
        //         if (this.index == 2) {
        //             $ionicScrollDelegate.$getByHandle('mainScroll').scrollTo(90, 0, true);
        //             $scope.payStatusStage = 2;
        //         }
        //         if (this.index == 3) {
        //             $ionicScrollDelegate.$getByHandle('mainScroll').scrollTo(230, 0, true);
        //             $scope.payStatusStage = 3;
        //         }
        //         if (this.index == 4) {
        //             $ionicScrollDelegate.$getByHandle('mainScroll').scrollTo(300, 0, true);
        //             $scope.payStatusStage = 4;
        //         }
        //         if (this.index == 5) {
        //             $scope.payStatusStage = 5;
        //         }
        //         $scope.pager.pageNo = 1;
        //         $scope.pager.pageSize = 10;
        //
        //         isFirstLoad = true;
        //         $scope.outOrderList = [];
        //         $scope.loadMore();
        //     }
        // }

        function clearClass() {
            //console.log('clearclass');
            for (var i = 0; i < sledivs.length; i++) {
                sledivs[i].className = '';
            }
        }
        function sleNav(index){
            clearClass();
            //console.log(index);
            //console.log(sledivs[index]);
            sledivs[index].className = 'w4-prolist-sle';
        }
        $scope.scrollGoto = function(index){

            $timeout(function(){
                if(index == 1){
                    $ionicScrollDelegate.$getByHandle('mainScroll').scrollTo(0,0);
                }else {
                    $ionicScrollDelegate.$getByHandle('mainScroll').scrollTo(index*100,0);
                }

            },50);
        };
        if($stateParams.statusStage){
            $scope.payStatusStage = $stateParams.statusStage;
            //根据参数跳转选择菜单
            if($stateParams.statusStage){
                var sletype = $stateParams.statusStage;
                $scope.index = sletype;
                sleNav(sletype);
                $scope.scrollGoto(sletype);

            }
        }

        $scope.canceReservation = function(id){
            var myPopup = $ionicPopup.show({
                title: '是否取消预约',
                scope: $scope,
                buttons: [
                    {
                        text: '取消',
                        type: 'button-default'
                    },
                    {
                        text: '确定',
                        type: 'button-positive confirmLogin',
                        onTap: function (e) {
                            $faAPI.order.orderStatus({
                                orderId:id,
                                updateType:'cancel'
                            }).then(function () {
                                $faPopup.alert({
                                    title: '取消预约成功'
                                });
                                $scope.outOrderList = [];
                                $scope.pager.payStatusStage = $scope.payStatusStage;

                                $faAPI.order.list($scope.pager).then(function (json) {
                                    if (json) {
                                        $scope.outOrder = json;

                                        if ($scope.outOrderList && $scope.outOrderList.length >= 1) {
                                            $scope.outOrderList = $scope.outOrderList.concat(json.list);
                                        } else {
                                            $scope.outOrderList = json.list;
                                        }
                                        $scope.pager = json.pager;
                                        $scope.$broadcast('scroll.infiniteScrollComplete');
                                    }
                                });
                            });

                        }
                    }
                ]
            });
        };
        $scope.ckisRebateConfirm = function(id){
            var myPopup = $ionicPopup.show({
                title: '是否确认返佣',
                scope: $scope,
                buttons: [
                    {
                        text: '取消',
                        type: 'button-default'
                    },
                    {
                        text: '确定',
                        type: 'button-positive confirmLogin',
                        onTap: function (e) {
                            $faAPI.order.orderStatus({
                                orderId:id,
                                updateType:'rebateConfirm'
                            }).then(function () {
                                $faPopup.alert({
                                    title: '确认返佣成功'
                                });
                                $scope.outOrderList = [];
                                $scope.pager.payStatusStage = $scope.payStatusStage;

                                $faAPI.order.list($scope.pager).then(function (json) {
                                    if (json) {
                                        $scope.outOrder = json;

                                        if ($scope.outOrderList && $scope.outOrderList.length >= 1) {
                                            $scope.outOrderList = $scope.outOrderList.concat(json.list);
                                        } else {
                                            $scope.outOrderList = json.list;
                                        }
                                        $scope.pager = json.pager;
                                        $scope.$broadcast('scroll.infiniteScrollComplete');
                                    }
                                });
                            });

                        }
                    }
                ]
            });
        }
        $scope.goTop = function(index){
            $ionicScrollDelegate.scrollTop();
            $scope.scrollGoto(index);

        };

    })

    .controller('myBankListCtrl',function($scope,$stateParams,$faAPI,$faModal,$ionicPopup,$state,$ionicActionSheet){
        $scope.data = {};
        //解绑卡ID
        var cardId;
        var myPopup;
        function getBankList(){
            //我的银行卡
            $faAPI.user.queryBingdingCard().then(function(res){
                $scope.res = res;
              console.log(res)
            });
        }
        getBankList();

        //解绑银行卡--操作表在android 有样式兼容性问题，使用弹窗
        $scope.delBank = function(cardId){
            cardId = cardId;
            $ionicPopup.confirm({
                title: '解除绑定银行卡',
                cancelText:'取消',
                okText:'确定',
                cancelType:'',
                okType:'button-assertive'
            }).then(function(res) {

                if(res){


                      //解绑
                      $faAPI.pay.releaseBindbankcard({
                          cardId:cardId
                      }).then(function(){
                          getBankList();
                      });



                    return
                    //是否有交易密码
                    // $faAPI.pay.isExistTradePwdBindingCard().then(function(res){
                    //     if(res.tradePwd == 1) {
                    //
                    //         myPopup = $ionicPopup.show({
                    //             //template: '<div style="width: 100%; text-align: center;" ><div style="width: 80%; background-color: #efefef; margin: 0 auto; border-radius: 2px; border: 1px solid #e4e4e4;"> <input type="password" name="wp" spellcheck="false" placeholder="请输入交易密码" ng-model="data.password" style="width: 110px; margin: 0 auto; background: none; text-align: center;" maxlength="6"> </div> <div ng-click="toForgetTradePwd()" style="text-align: right;font-size: 12px; color: #ff7000; position: relative; top: 10px;">忘记交易密码?</div> </div>',
                    //             template: '<div style="width: 100%; text-align: center;" ><div style="width: 80%; background-color: #efefef; margin: 0 auto; border-radius: 2px; border: 1px solid #e4e4e4;"> <input type="password" name="wp" spellcheck="false" placeholder="请输入交易密码" ng-model="data.password" style="width: 110px; margin: 0 auto; background: none; text-align: center;" maxlength="6"> </div> </div>',
                    //           title: '请输入交易密码',
                    //             scope: $scope,
                    //             buttons: [
                    //                 { text: '取消' },
                    //                 {
                    //                     text: '<b>确认</b>',
                    //                     type: 'button-default',
                    //                     onTap: function(e) {
                    //                         if (!$scope.data.password) {
                    //                             e.preventDefault();
                    //                         } else {
                    //                             return $scope.data.password;
                    //                         }
                    //                     }
                    //                 }
                    //             ]
                    //         });
                    //
                    //
                    //     }else {
                    //         $state.go('app.tradePassword');
                    //     }
                    // })
                }
            });

        };
        //$faModal('tradePwd','views/pay/importPwd.html',$scope,{
        //    done:function(){
        //        var self = this;
        //        $faAPI.user.checkTradePwd({
        //            tradePwd:$scope.req.tradePwd
        //        }).then(function(){
        //            $faAPI.pay.releaseBindbankcard().then(function(res){
        //                self.hide();
        //                getBankList();
        //            });
        //        });
        //    }
        //});
    })

    // .controller('myselfSetTradePasswordCtrl', function ($scope, $stateParams, $faAPI, $faUser, $faModal, $faPopup, $state, $rootScope) {
    //   $scope.trade = {
    //     tradePwd: ''
    //   };
    //
    //   $scope.setTradePassword = function () {
    //     if (!$scope.trade.tradePwd) {
    //       $faPopup.alert({
    //         title: '请输入交易密码！'
    //       });
    //       return;
    //     }
    //     if ($scope.trade.tradePwd.length != 6) {
    //       $faPopup.alert({
    //         title: '交易密码必须为六位！'
    //       });
    //       return;
    //     }
    //     if ($scope.trade.tradePwd != $scope.trade.tradePwd2) {
    //       $faPopup.alert({
    //         title: '两次交易密码输入不一致！'
    //       });
    //       return;
    //     }
    //
    //     $faAPI.pay.setPayPwd($scope.trade).then(function (json) {
    //       if (json) {
    //         $faPopup.alert({
    //           title: '设置交易密码成功！'
    //         });

            //if ($rootScope.doWithdraw) {
            //  $state.go('app.withdraw.do', {id: $rootScope.doWithdraw || 0});
            //} else {
            //  $state.go('app.myself');
            //}
    //         $state.go('myBankList',{goid:'1'});
    //       }
    //     });
    //   }
    // })
